package com.kexio.common.enums;

/**
 * 通用状态枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum StatusEnum {
    
    /**
     * 启用
     */
    ENABLED(1, "启用"),
    
    /**
     * 禁用
     */
    DISABLED(0, "禁用");
    
    private final Integer code;
    private final String desc;
    
    StatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    
    public Integer getCode() {
        return code;
    }
    
    public String getDesc() {
        return desc;
    }
    
    /**
     * 根据code获取枚举
     */
    public static StatusEnum fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (StatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的状态码: " + code);
    }
    
    /**
     * 判断是否启用
     */
    public boolean isEnabled() {
        return this == ENABLED;
    }
    
    /**
     * 判断是否禁用
     */
    public boolean isDisabled() {
        return this == DISABLED;
    }
    
    @Override
    public String toString() {
        return "StatusEnum{" +
                "code=" + code +
                ", desc='" + desc + '\'' +
                '}';
    }
}
